package com.jack.leetcode.eachproblem_2020;

public class 翻转矩阵后的得分 {

    public static void main(String[] args) {
        int[][] A = {{0,0,1,1},{1,0,1,0},{1,1,0,0}};
        System.out.println(matrixScore(A));
    }

    public static int matrixScore(int[][] A) {
        int result = 0;
        for(int[] a : A){
            if(a[0] == 0){
                for(int i = 0;i < a.length;i++){
                    a[i] = 1 - a[i];
                }
            }
        }
        for(int j = 1;j < A[0].length;j++){
            int zeroNumbers = 0;
            for(int i = 0;i < A.length;i++){
                if(A[i][j] == 0){
                    zeroNumbers++;
                }
            }
            if(A.length - zeroNumbers < zeroNumbers){
                for(int i = 0;i < A.length;i++){
                    A[i][j] = 1 - A[i][j];
                }
            }
        }
        for(int[] a : A){
            int two = 1;
            for(int i = a.length - 1;i >= 0;i--){
                if(a[i] == 1){
                    result += two;
                }
                two *= 2;
            }
        }
        return result;
    }
}
